<!DOCTYPE HTML>
<html>
<head>
<title>接口文档</title>
<meta name='referrer' content='always'/>
<meta name='keywords' content='接口文档'/>
<meta name='description' content='接口文档'/>
<link id='IconLink' rel='shortcut icon' href='/favicon.ico'/>
<meta http-equiv='x-ua-compatible' content='ie=edge,chrome=1'/>
<meta http-equiv='content-type' content='text/html; charset=utf-8'/>
<meta name='viewport' content='width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no'/>

<script>
if (typeof(require) == 'function') delete window.module;
</script>

<script src='/res/lib/utils.js.gzip'></script>

<style>
html{
	height: 100%;
	font-size: 13px;
}
#MainDiv{
	padding: 0vh 5vw;
}
#QueryDiv{
	margin-top: 1vh;
	margin-bottom: 3vh;
}
#FooterDiv{
	padding-top: 48px;
	padding-bottom: 48px;
}
#ContentDiv{
	min-height: 70vh;
}
#ShowSideDiv{
	top: -1px;
	left: -1px;
	width: 24px;
	height: 24px;
	z-index: 1000;
	display: none;
	position: fixed;
	background-size: 90% 90%;
	background-position: center;
	background-repeat: no-repeat;
	background-image: url(/res/img/list.png);
}
.MenuBarSpan{
	font-family: 宋体;
	font-size: 0.9rem;
}
.MobileSideDiv{
	top: 0px;
	left: 0px;
	width: 100%;
	height: 100%;
	z-index: 100;
	position: fixed;
}
.CgiDocPathDiv{
	text-transform: uppercase;
}
.CgiDocRemarkDiv{
	top: -2px;
	position: relative;
}
</style>

<script>
var linkmap = null;
var curnode = null;
var doclist = null;
var clickflag = null;
var contentview = null;

function getLink(){
	var pos = window.location.href.indexOf('#');

	if (pos < 0) return null;

	var link = window.location.href.substring(pos);
	
	return decodeURIComponent(link);
}
function hideSideMenu(){
	$('#SideDiv').hide();
	$('#ShowSideDiv').show();
}
function showSideMenu(){
	$('#SideDiv').show();
	$('#ShowSideDiv').hide();
}
function updateView(doclist, filter){
	var pos = null;
	var key = null;
	var title = null;
	var folder = null;
	var parent = null;
	let sideview = $('#SideDiv');
	let menuview = $('#MenuDiv');

	pos = getLink();
	key = 'document_location_cgidoc';

	if (pos == null) pos = getStorage(key);

	var group = [];
	var accesslist = [
			"<span style='line-height:16px;font-size:0.8rem;color:#888'>[停用]</span>",
			"<span style='line-height:16px;font-size:0.8rem;color:#090'>[私有]</span>",
			"<span style='line-height:16px;font-size:0.8rem;color:#37F'>[内部]</span>",
			"<span style='line-height:16px;font-size:0.8rem;color:#D00'>[公开]</span>"
	];

	menuview.children().remove();
	menuview.width(sideview.width());
	menuview.height(sideview.height());

	linkmap = new Map();
	curnode = null;
	function getText(text, title, access){
		if (access){
			return "<span class='MenuBarSpan' style='display:inline-block;padding-bottom:2px;text-transform:uppercase;letter-spacing:1px' title='" + title + "'>" + text + "</span><span class='MenuBarSpan' style='float:right;padding-top:2px'>" + title + "&nbsp;" + accesslist[access] + "</span>";
		}
		else{
			return "<span class='MenuBarSpan' style='display:inline-block;padding-bottom:4px;letter-spacing:0px' title='" + title + "'>" + text + "</span>";
		}
	}

	if (filter) filter = filter.toLowerCase();

	$.each(doclist, function(idx, item){
		if (item.remark == null) item.remark = '';

		var link = '#' + item.folder + '/' + item.title;

		if (filter && item.title.indexOf(filter) < 0 && item.remark.indexOf(filter) < 0) return;

		if (folder != item.folder){
			folder = item.folder;
			parent = new MenuBar(menuview, getText(folder, ''), '/res/img/menu/server.png', group);
		}

		var node = parent.add(getText(item.title, item.remark, item.enabled), '/res/img/menu/link.png', function(){
			if (item.content == null) item.content = getHttpResult(item.url);
			if (machinetype == 'MOBILE') hideSideMenu();

			curnode = node;
			clickflag = true;
			node.menubar.open();
			setStorage(key, link);
			window.location.href = link;
			contentview.html(item.content);
			$('.CgiDocPathDiv').css('letter-spacing', '3px');
		});

		if (pos == link || curnode == null) curnode = node;

		linkmap.set(link, node);
	});

	if (machinetype == 'MOBILE') $('#MainDiv').css('padding-right', '2vw');

	$('#FooterDiv').load('/sharenote?flag=S&title=FOOTER');

	if (parent){
		menuview.css('background', parent.color().listcolor);
		if (curnode) curnode.click();
	}
}

window.onload = function(){
	contentview = $('#ContentDiv');

	if (machinetype == 'PC'){
		setFrameStyle('TopDiv', 'SideDiv', 'MainDiv', 'BottomDiv', 0, 380, 0, 0);

		QueryWidget('QueryDiv', '输入接口编号或描述', '查找', function(text){
			updateView(doclist, text.val());
		});
	}
	else{
		$('#TopDiv').remove();
		$('#BottomDiv').remove();
		$('#SideDiv').addClass('MobileSideDiv');

		hideSideMenu();

		$('#ShowSideDiv').click(showSideMenu);
	}

	function popstate(){
		var link = getLink();
		var node = linkmap.get(link) || curnode;

		if (node){
			if (clickflag){
				clickflag = false;
			}
			else{
				node.click();
			}
		}
	}

	window.onhashchange = popstate;
	window.onpopstate = popstate;

	getHttpResult('/getcgidoclist', {key: '@'}, function(data){
		if (data.list) updateView(doclist = data.list);
	});
}
</script>
</head>

<body>
	<div id='TopDiv'></div>
	<div id='SideDiv'>
		<div style='width:100%;height:100%;position:relative;overflow:hidden'>
			<div style='overflow-x:hidden;overflow-y:scroll;position:absolute'>
				<div id='MenuDiv'></div>
			</div>
		 </div>
	</div>
	<div id='MainDiv'>
		<div id='QueryDiv'></div>
		<div id='ContentDiv'></div>
		<div id='FooterDiv'></div>
	</div>
	<div id='BottomDiv'></div>
	<div id='ShowSideDiv'></div>
</body>
</html>